# coding=utf-8
from framework.base_page import BasePage
import time


class Agency_orderPage(BasePage):
    own_order = "xpath=>//*[@id='root']/div/div/div/div[2]/div[1]/div[2]/button"

    # 标签
    tag_all = "c=>ant-radio-button-wrapper"
    tag_arriving_num = 1
    tag_arrived_num = 2
    tag_sailed_num = 3

    # 搜索按钮
    Advanced_Search = "x=>//*[@id='root']/div/div/div/div[2]/div[2]/div/div[2]/div/form/div[1]/div/div[2]/div/div[1]/a/i"
    hide_search = "x=>//*[@id='root']/div/div/div/div[2]/div[2]/div/div[2]/div/form/div[2]/div[2]/div/div/div[1]/a/i"
    reset = "x=>//*[@id='root']/div/div/div/div[2]/div[2]/div/div[2]/div/form/div[1]/div/div[2]/div/div[1]/button[1]"
    search = "c=>ant-btn-primary"

    # 搜索项
    # 浮框插件
    out = "ant-select-dropdown-menu-vertical"
    nei = "ant-select-dropdown-menu-item"
    # 船舶
    ship = "c=>ant-select-selection__rendered"
    ship_text = "id=>ship"
    ship_value = "12345"
    ship_name ="2343456 - 12345"

    # 委托方
    inquirer_num = 2
    inquirer_text = "id=>consigner"
    inquirer_value = "xingchen"

    # 订单状态
    status_num = 3
    status_text = "id=>status"
    status_value = "服务中"

    # 船期
    ETA = ""
    ETA_text = ""

    # 服务类型
    service_type_num = 4
    service_type_text = "id=>type"
    service_type_value = "husbandry"

    # 询价单号
    order_no_num = 5
    order_no_text = "id=>orderNumber"
    order_no_value = "9726"
    order_no_name = "EP0020191217173119726"

    # 排序
    list_by_creat_data = ""
    list_by_ETA = ""

    def tag_all_button(self):
        self.click(self.tag_all)

    def tag_arriving_button(self):
        self.clicks(self.tag_all, num=self.inquirer_num)

    def tag_arrived_button(self):
        self.clicks(self.tag_all, num=self.tag_arrived_num)

    def tag_sailed_button(self):
        self.clicks(self.tag_all, num=self.tag_sailed_num)

    # 查询项
    def input_select(self, a, b, value_1, value_2, num_1=0, num_2=1):
        if len(value_1) > 0:
            self.clicks(a, num_1)
            self.types(b, text=value_1, num=num_2)
            time.sleep(2)
            # WebDriverWait(self.driver, 10).until(
            # lambda the_driver: self.driver.find_elements_by_class_name("ant-select-dropdown-menu-vertical")[
            # -1].is_displayed()
            # )
            menu = self.driver.find_elements_by_class_name(self.out)[
                -1].find_elements_by_class_name(self.nei)
            for i in range(0, len(menu)):
                if value_2 in menu[i].get_attribute("textContent"):
                    # webdriver.ActionChains(self.driver).move_to_element(menu[i]).click(menu[i]).perform()
                    menu[i].click()
            try:
                assert (value_2, self.get_labels(a, num=num_1))
                print("input success:%s" % self.get_labels(a, num=num_1))
            except Exception:
                print("input fail", format(Exception))
                raise

    # 按钮
    def Advanced_Search_button(self):
        self.click(self.Advanced_Search)

    def hide_button(self):
        self.click(self.hide_search)

    def reset_button(self):
        self.click(self.reset)

    def search_button(self):
        self.clicks(self.search, num=2)

    # 排序
    def list_by_creat_button(self):
        self.click(self.list_by_creat_data)

    def list_by_ETA_button(self):
        self.click(self.list_by_ETA)